const { mock } = require("mockjs")
const { lodash } = require('lodash');

const totalCount = 3
const List = [
  {
    id: '@id',
    roomNo: 'DA076',
    roomName: '温度报警器',
    equipmentType: [{ name: '温度', type: 'danger' }, { name: '红外', type: 'success' }, { name: '视频', type: 'info' }],
    statusLabel: '关闭',
    status: '3',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'WJ006',
    roomName: '文件保管室',
    equipmentType: [{ name: '红外', type: 'success' }, { name: '视频', type: 'info' }],
    statusLabel: '运行中',
    status: '2',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'GL012',
    roomName: '锅炉房',
    equipmentType: [{ name: '温度', type: 'danger' }, { name: '红外', type: 'success' }],
    statusLabel: '已上线',
    status: '1',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'LD008',
    roomName: '主任办公室',
    equipmentType: [{ name: '红外', type: 'success' }, { name: '视频', type: 'info' }, { name: '温度', type: 'danger' }],
    statusLabel: '已上线',
    status: '1',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'LD021',
    roomName: '处长办公室',
    equipmentType: [{ name: '温度', type: 'danger' }, { name: '视频', type: 'info' }],
    statusLabel: '运行中',
    status: '2',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'JSJ012',
    roomName: '计算机室',
    equipmentType: [{ name: '红外', type: 'success' }, { name: '视频', type: 'info' }, { name: '温度', type: 'danger' }],
    statusLabel: '异常',
    status: '4',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'JMWJ098',
    roomName: '机密文件保管库房',
    equipmentType: [{ name: '视频', type: 'info' }],
    statusLabel: '运行中',
    status: '2',
    description: '这是描述',
    updated: '@datetime',
  },
  {
    id: '@id',
    roomNo: 'TSG028',
    roomName: '图书馆',
    equipmentType: [{ name: '温度', type: 'danger' }],
    statusLabel: '运行中',
    status: '2',
    description: '这是描述',
    updated: '@datetime',
  }
]
module.exports = [
  {
    url: '/roomManagement/getList',
    type: 'post',
    response(config) {
      const { title = '', pageNo = 1, pageSize = 20 } = config.body
      let mockList = List.filter((item) => {
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })
      const pageList = mockList.filter(
        (item, index) =>
          index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
      )
      return {
        code: 200,
        msg: 'success',
        totalCount,
        data: pageList,
      }
    },
  },
  {
    url: '/roomManagement/doEdit',
    type: 'post',
    response() {
      return {
        code: 200,
        msg: '模拟保存成功',
      }
    },
  },
  {
    url: '/roomManagement/doDelete',
    type: 'post',
    response() {
      return {
        code: 200,
        msg: '模拟删除成功',
      }
    },
  },
  {
    url: '/roomManagement/doGetRoomInfo',
    type: 'post',
    response(config) {
      const { roomNo } = config.body
      return {
        code: 200,
        msg: 'success',
        data: List.find((item) => { return item.roomNo == roomNo })
      }
    }
  }
]
